<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="../templates/principal.xhtml">

    <ui:define name="head">
        <script type="text/javascript">
            function handleClienteRequest(xhr, status, args) {
                if (args.validationFailed || !args.loggedIn) {
                    PF('propostaDialog').show();
                } else {
                    PF('propostaDialog').hide();
                }
            }


        </script>
    </ui:define>

    <ui:define name="content" id="content">
        <h:form id="frmProposta">
            <p:panel id="panel" header="Bem Vindo as Propostas não Aprovadas">
                <p:growl id="messages" life="5000" />

                <p:dataTable id="tabProposta" widgetVar="wtabProposta" var="proposta" value="#{propostaBean.lazyModel}" 
                             lazy="true" paginator="true" rows="12" paginatorPosition="top"
                             emptyMessage="Nenhum Registro Retornado ..." filterEvent="enter" resizableColumns="true">

                    <f:facet name="header">
                        STATUS: 9 - Propostas não Aprovadas
                    </f:facet>

                    <p:column headerText="Numero Proposta" sortBy="#{proposta.numProposta}" filterBy="#{proposta.numProposta}">
                        <div style="text-align: left;">
                            <h:outputText value="#{proposta.numProposta}" />
                        </div>
                    </p:column>

                    <p:column headerText="Empreendimento" sortBy="#{proposta.idEmpreendimento.dscEmpreendimento}" filterBy="#{proposta.idEmpreendimento.dscEmpreendimento}">
                        <div style="text-align: left; ">
                            <h:outputText value="#{proposta.idEmpreendimento.dscEmpreendimento}" />
                        </div>
                    </p:column>

                    <p:column headerText="Assunto" sortBy="#{proposta.dscProposta}" filterBy="#{proposta.dscProposta}">
                        <div style="text-align: left; ">
                            <h:outputText value="#{proposta.dscProposta}" />
                        </div>
                    </p:column>

                    <p:column headerText="Empresa" sortBy="#{proposta.idEmpresa.nomEmpresa}" filterBy="#{proposta.idEmpresa.nomEmpresa}">
                        <div style="text-align: left; ">
                            <h:outputText value="#{proposta.idEmpresa.nomEmpresa}" />
                        </div>
                    </p:column>

                    <p:column headerText="Cliente Fantasia/Sobrenome" sortBy="#{proposta.idCliente.nomFantasia}" filterBy="#{proposta.idCliente.nomFantasia}">
                        <div style="text-align: left; ">
                            <h:outputText value="#{proposta.idCliente.nomFantasia}" />
                        </div>
                    </p:column>

                    <p:column>
                        <h:panelGrid columns="4" styleClass="actions" cellpadding="0">
                            <p:commandButton id="selectButtonProposta" update=":frmProposta:panel :frmProposta:messages" 
                                             icon="ui-icon-search" title="Visualizar Proposta" oncomplete="PF('propostaDialog').show();  propostaDialog.toggleMaximize();">
                                <f:setPropertyActionListener value="#{proposta}" target="#{propostaBean.selectedProposta}" />
                                <f:setPropertyActionListener value="#{false}" target="#{propostaBean.ativa}" />
                            </p:commandButton>
                        </h:panelGrid>
                    </p:column>
                </p:dataTable>

                <!-- DETALHES PROPOSTA -->
                <p:dialog id="dialog" header="Detalhes Proposta" widgetVar="propostaDialog" resizable="true" dynamic="true" 
                          onHide="PF('propostaDialog').hide(); propostaDialog.toggleMaximize();"
                          width="1500" showEffect="explode" hideEffect="explode" style="text-align: left" position="top" maximizable="true">

                    <p:panel id="panelDetalhe" style="text-align: left; ">
                        <p:panelGrid id="display" style="margin-bottom:50px; text-align: left; width: 100%;">

                            <p:row>
                                <p:column colspan="7">
                                    <h:outputText value="Numero Proposta: #{propostaBean.selectedProposta.numProposta}" style="font-weight:bold;" />
                                </p:column>
                            </p:row>

                            <p:row>
                                <p:column>
                                    <h:outputText value="* Assunto:" />
                                </p:column>
                                <p:column colspan="3">
                                    <p:inputText id="inDescricao" value="#{propostaBean.selectedProposta.dscProposta}" readonly="true" maxlength="100" style="width:800px; font-weight:bold; " />
                                </p:column>
                            </p:row>

                            <p:row>
                                <p:column>
                                    <h:outputText value="Empresa:" />
                                </p:column>
                                <p:column colspan="3">
                                    <p:inputText id="inEmpresa" value="#{propostaBean.selectedProposta.idEmpresa.nomEmpresa}" readonly="true" maxlength="100" style="width:800px; font-weight:bold; " />
                                </p:column>
                            </p:row>

                            <p:row>
                                <p:column>
                                    <h:outputText value="* Cliente:" />
                                </p:column>
                                <p:column>
                                    <p:inputText id="inCliente" value="#{propostaBean.selectedProposta.idCliente.nomCliente}" 
                                                 readonly="true" style="width:500px; font-weight:bold; " />

                                    <!-- <p:commandButton icon="ui-icon ui-icon-search" title="Pesquisar Cliente" update=":frmProposta:panelCliente" onclick="clienteDialog.show();" /> -->
                                </p:column>
                                <p:column>
                                    <h:outputText value="Empreendimento:" />
                                </p:column>
                                <p:column>
                                    <p:inputText id="inEmpreendimento" value="#{propostaBean.selectedProposta.nomEmpreendimento}" 
                                                 readonly="true" style="width:500px; font-weight:bold; " />
                                </p:column>
                            </p:row>

                            <p:row> 
                                <p:column>
                                    <h:outputText value="Data Proposta:" />
                                </p:column>
                                <p:column colspan="3">
                                    <p:inputMask readonly="true" id="imDatAbert" value="#{propostaBean.selectedProposta.datProposta}" mask="99/99/9999" style="font-weight:bold; ">
                                        <f:convertDateTime type="date" dateStyle="short" pattern="dd/MM/yyyy" />
                                    </p:inputMask>
                                </p:column>
                            </p:row>

                            <p:row>
                                <p:column>
                                    <h:outputText value="Modelo Proposta:" />
                                </p:column>
                                <p:column colspan="4">
                                    <p:inputText id="inModeloProposta" value="#{propostaBean.selectedProposta.dscModelo}" 
                                                 readonly="true" style="width:500px; font-weight:bold; " />
                                </p:column>
                            </p:row>

                            <p:row>
                                <p:column colspan="4" headerText="Proposta">
                                    <p:inputTextarea autoResize="false" rows="35"  id="editorModelo" widgetVar="weditorModelo" value="#{propostaBean.selectedProposta.modelo}" style="width:100%;" />
                                </p:column>
                            </p:row>
                        </p:panelGrid>
                    </p:panel>
                </p:dialog>

                
            </p:panel>

        </h:form>
    </ui:define>
</ui:composition>